/*
101. 对称二叉树

给你一个二叉树的根节点 root ， 检查它是否轴对称。
 */
package LC0101;

import org.w3c.dom.Node;

class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;

    TreeNode() {
    }

    TreeNode(int val) {
        this.val = val;
    }

    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}

class Solution1 {
    public static void main(String[] args) {
        TreeNode test = null;
        System.out.println(test.val);
    }

    // 迭代
    public boolean isSymmetric(TreeNode root) {
        if (root == null) {
            return false;
        }

        return NodeSymmetric(root.left, root.right);
    }

    public boolean NodeSymmetric (TreeNode left, TreeNode right){
        // TODO 为什么这个判断放在下面会显示 condition is always false ???
            // 如果是null，那么left.val != right.val的判断根本不会发生
            // 如果判断可以进行，那么就不是null，因此 condition is always false
        if (left == null && right == null){
            return true;
        }

        if (left == null || right == null){
            return false;
        }

        if (left.val != right.val){
            return false;
        }

        return NodeSymmetric(left.left, right.right) && NodeSymmetric(left.right, right.left);
    }
}
